﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace onPulse01
{
    public partial class Filter : PhoneApplicationPage
    {
        public Filter()
        {
            InitializeComponent();
            
            countRadio.IsChecked = false;
            diastolicRadio.IsChecked = false;
            systolicRadio.IsChecked = true;

            countPanel.Visibility = System.Windows.Visibility.Collapsed;
            diastolicText.Visibility = System.Windows.Visibility.Collapsed;
            systolicText.Visibility = System.Windows.Visibility.Visible;
        }
		
        private void countRadio_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
            if(countPanel != null) countPanel.Visibility = System.Windows.Visibility.Visible;
        }

        private void diastolicRadio_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
            if(diastolicText != null) diastolicText.Visibility = System.Windows.Visibility.Visible;
        }

        private void systolicRadio_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
            if(systolicText != null) systolicText.Visibility = System.Windows.Visibility.Visible;
        }

        private void systolicRadio_Unchecked(object sender, System.Windows.RoutedEventArgs e)
        {
            if (systolicText != null) systolicText.Visibility = System.Windows.Visibility.Collapsed;
        }
		
		private void diastolicRadio_Unchecked(object sender, System.Windows.RoutedEventArgs e)
        {
            if (diastolicText != null) diastolicText.Visibility = System.Windows.Visibility.Collapsed;
        }
		
		private void countRadio_Unchecked(object sender, System.Windows.RoutedEventArgs e)
        {
            if (countPanel != null) countPanel.Visibility = System.Windows.Visibility.Collapsed;
        }

		private void SaveBtn_Click(object sender, System.EventArgs e)
		{
            if (systolicRadio.IsChecked.Value) MainPage.resultsDelegate.Results = MainPage.filterDataBSystolic(Convert.ToInt32(systolicSliderG.Value), Convert.ToInt32(systolicSliderD.Value));
            else if (diastolicRadio.IsChecked.Value) MainPage.resultsDelegate.Results = MainPage.filterDataByDiastolic(Convert.ToInt32(diastolicSliderD.Value), Convert.ToInt32(diastolicSliderG.Value));
            else if (countRadio.IsChecked.Value) MainPage.resultsDelegate.Results = MainPage.filterDataByCount(Convert.ToInt32(countSlider.Value));
            this.NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
		}

		private void CancelBtn_Click(object sender, System.EventArgs e)
		{
            this.NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
		}

		private void Slider_ValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs<double> e)
		{
            Slider slider = (Slider)sender;
            slider.Value = Math.Round(slider.Value);
		}
    }
}